<template>
	<view class="statistics">
		<gyd-navbar back-color="#fff" :title="title" :isBack="false"></gyd-navbar>

		<gyd-tabs :current="params.current" :list="tabsList" @clickItem="changeTab"></gyd-tabs>

		<!-- 底部导航栏 -->
		<gyd-tabbar :current="1"></gyd-tabbar>
	</view>
</template>

<script setup>
	import request from '@/utils/request';
	import cache from '@/utils/cache';
	import util from '@/utils/util';
	import {
		ref,
		reactive,
		toRefs,
		inject,
	} from 'vue';
	import {
		onLoad,
		onShow,
		onReady,
		onPullDownRefresh,
		onReachBottom,
	} from '@dcloudio/uni-app';

	const state = reactive({
		title: '统计',
		themeColor: cache.get('themeColor'),
		imgHost: util.requestUrl(),
		tabsList: ['我的客户', '我的团队', '我的商户'],
		params: {
			current: 0,
			skip: 0,
		},
		isMore: true,
		list: [],
	});

	//在页面所有元素加载完成后执行（只执行一次）
	onLoad((opt) => {
		console.log('onLoad');
		if (opt.hasOwnProperty('current')) {
			console.log('传递参数', opt.current);
			state.params.current = opt.current;
		}
		getDataList();
	});

	//在页面由不可见变为可见时执行（只要页面显示都会执行）
	onShow(() => {
		console.log('onShow');
	})

	//在页面解析完成之后执行
	onReady(() => {
		console.log('onReady');
	})

	onPullDownRefresh(() => {
		console.log('下拉刷新');
		setTimeout(() => {
			uni.stopPullDownRefresh();
		}, 1000);
		state.isMore = true;
		state.list = [];
		getDataList();
	})

	onReachBottom(() => {
		console.log('触底加载更多');
		getDataList();
	})

	function getDataList() {

	}

	function changeTab(index) {
		state.params.current = index;
		state.isMore = true;
		state.list = [];
		getDataList();
	}

	function pageRoute(url) {
		uni.navigateTo({
			url
		});
	}

	function pageTabRoute(url) {
		uni.reLaunch({
			url
		});
	}

	const {
		title,
		themeColor,
		imgHost,
		tabsList,
		params,
		isMore,
		list
	} = toRefs(state);
</script>

<style lang="scss">
	.statistics {}
</style>